<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工代码" prop="fnumber">
        <el-input
          v-model="queryParams.fnumber"
          placeholder="请输入员工代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工名称" prop="fname">
        <el-input
          v-model="queryParams.fname"
          placeholder="请输入员工名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一级法人" prop="fsscompany">
        <el-input
          v-model="queryParams.fsscompany"
          placeholder="请输入一级法人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="所属成本中心" prop="fsscost">
        <el-input
          v-model="queryParams.fsscost"
          placeholder="请输入所属成本中心"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工资承担公司" prop="fgzcdgs">
        <el-input
          v-model="queryParams.fgzcdgs"
          placeholder="请输入工资承担公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工资发放公司" prop="fgzffgs">
        <el-input
          v-model="queryParams.fgzffgs"
          placeholder="请输入工资发放公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保承担公司" prop="fsbcdgs">
        <el-input
          v-model="queryParams.fsbcdgs"
          placeholder="请输入社保承担公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保发放公司" prop="fsbffgs">
        <el-input
          v-model="queryParams.fsbffgs"
          placeholder="请输入社保发放公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金承担公司" prop="fgjjcdgs">
        <el-input
          v-model="queryParams.fgjjcdgs"
          placeholder="请输入公积金承担公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金发放公司" prop="fgjjffgs">
        <el-input
          v-model="queryParams.fgjjffgs"
          placeholder="请输入公积金发放公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工资发放金融机构" prop="fgzffjrjg">
        <el-input
          v-model="queryParams.fgzffjrjg"
          placeholder="请输入工资发放金融机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工资发放金融机构银行账户" prop="fgzffyhzh">
        <el-input
          v-model="queryParams.fgzffyhzh"
          placeholder="请输入工资发放金融机构银行账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保发放金融机构" prop="fsbffjrjg">
        <el-input
          v-model="queryParams.fsbffjrjg"
          placeholder="请输入社保发放金融机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保发放金融机构银行账户" prop="fsbffyhzh">
        <el-input
          v-model="queryParams.fsbffyhzh"
          placeholder="请输入社保发放金融机构银行账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金发放金融机构" prop="fgjjffjrjg">
        <el-input
          v-model="queryParams.fgjjffjrjg"
          placeholder="请输入公积金发放金融机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公积金发放金融机构银行账户" prop="fgjjffyhzh">
        <el-input
          v-model="queryParams.fgjjffyhzh"
          placeholder="请输入公积金发放金融机构银行账户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否跨一级法人公司" prop="fiskyjfr">
        <el-input
          v-model="queryParams.fiskyjfr"
          placeholder="请输入是否跨一级法人公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单人" prop="fcreator">
        <el-input
          v-model="queryParams.fcreator"
          placeholder="请输入制单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单时间" prop="fcreatetime">
        <el-date-picker clearable
          v-model="queryParams.fcreatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择制单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最后修改人" prop="flastupdateuser">
        <el-input
          v-model="queryParams.flastupdateuser"
          placeholder="请输入最后修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后修改时间" prop="flastupdatetime">
        <el-date-picker clearable
          v-model="queryParams.flastupdatetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最后修改时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          :disabled="single"
          @click="handleView"
        >查看</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wfzBaseData:person:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wfzBaseData:person:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wfzBaseData:person:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wfzBaseData:person:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="personList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="fid" />
      <el-table-column label="员工代码" align="center" prop="fnumber" />
      <el-table-column label="员工名称" align="center" prop="fname" />
      <el-table-column label="一级法人" align="center" prop="fsscompany" />
      <el-table-column label="所属成本中心编码" align="center" prop="fsscost" />
      <el-table-column label="所属成本中心名称" align="center" prop="fsscostname" />
      <el-table-column label="工资承担公司" align="center" prop="fgzcdgs" />
      <el-table-column label="工资发放公司" align="center" prop="fgzffgs" />
      <el-table-column label="成本中心所属财务组织" align="center" prop="fcostcompany" />
      <el-table-column label="社保承担公司" align="center" prop="fsbcdgs" />
      <el-table-column label="社保发放公司" align="center" prop="fsbffgs" />
      <el-table-column label="公积金承担公司" align="center" prop="fgjjcdgs" />
      <el-table-column label="公积金发放公司" align="center" prop="fgjjffgs" />
      <el-table-column label="工资发放金融机构" align="center" prop="fgzffjrjg" />
      <el-table-column label="工资发放金融机构银行账户" align="center" prop="fgzffyhzh" />
      <el-table-column label="社保发放金融机构" align="center" prop="fsbffjrjg" />
      <el-table-column label="社保发放金融机构银行账户" align="center" prop="fsbffyhzh" />
      <el-table-column label="公积金发放金融机构" align="center" prop="fgjjffjrjg" />
      <el-table-column label="公积金发放金融机构银行账户" align="center" prop="fgjjffyhzh" />
      <el-table-column label="是否跨一级法人公司" align="center" prop="fiskyjfr" />
      <el-table-column label="状态" align="center" prop="fstate">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bill_state" :value="scope.row.fstate"/>
        </template>
      </el-table-column>
      <el-table-column label="制单人" align="center" prop="fcreator" />
      <el-table-column label="制单时间" align="center" prop="fcreatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fcreatetime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后修改人" align="center" prop="flastupdateuser" />
      <el-table-column label="最后修改时间" align="center" prop="flastupdatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.flastupdatetime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wfzBaseData:person:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wfzBaseData:person:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改员工档案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="250px">

        <el-row>
          <el-col :span="8">
            <el-form-item label="员工代码" prop="fnumber">
              <el-input v-model="form.fnumber" placeholder="请输入员工代码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="员工名称" prop="fname">
              <el-input v-model="form.fname" placeholder="请输入员工名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="一级法人" prop="fsscompany">
              <el-input v-model="form.fsscompany" placeholder="请输入一级法人" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="所属成本中心编码" prop="fsscost">
              <el-input v-model="form.fsscost" placeholder="请输入所属成本中心编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属成本中心名称" prop="fsscostname">
              <el-input v-model="form.fsscostname" placeholder="请输入所属成本中心名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工资承担公司" prop="fgzcdgs">
              <el-input v-model="form.fgzcdgs" placeholder="请输入工资承担公司" />
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="工资发放公司" prop="fgzffgs">
              <el-input v-model="form.fgzffgs" placeholder="请输入工资发放公司" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="成本中心所属财务组织" prop="fcostcompany">
              <el-input v-model="form.fcostcompany" placeholder="请输入成本中心所属财务组织" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社保承担公司" prop="fsbcdgs">
              <el-input v-model="form.fsbcdgs" placeholder="请输入社保承担公司" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="社保发放公司" prop="fsbffgs">
              <el-input v-model="form.fsbffgs" placeholder="请输入社保发放公司" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金承担公司" prop="fgjjcdgs">
              <el-input v-model="form.fgjjcdgs" placeholder="请输入公积金承担公司" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金发放公司" prop="fgjjffgs">
              <el-input v-model="form.fgjjffgs" placeholder="请输入公积金发放公司" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="工资发放金融机构" prop="fgzffjrjg">
              <el-input v-model="form.fgzffjrjg" placeholder="请输入工资发放金融机构" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="工资发放金融机构银行账户" prop="fgzffyhzh">
              <el-input v-model="form.fgzffyhzh" placeholder="请输入工资发放金融机构银行账户" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="社保发放金融机构" prop="fsbffjrjg">
              <el-input v-model="form.fsbffjrjg" placeholder="请输入社保发放金融机构" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="社保发放金融机构银行账户" prop="fsbffyhzh">
              <el-input v-model="form.fsbffyhzh" placeholder="请输入社保发放金融机构银行账户" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金发放金融机构" prop="fgjjffjrjg">
              <el-input v-model="form.fgjjffjrjg" placeholder="请输入公积金发放金融机构" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公积金发放金融机构银行账户" prop="fgjjffyhzh">
              <el-input v-model="form.fgjjffyhzh" placeholder="请输入公积金发放金融机构银行账户" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="是否跨一级法人公司" prop="fiskyjfr">-->
<!--              <el-input v-model="form.fiskyjfr" placeholder="请输入是否跨一级法人公司" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->

          <el-col :span="8">
            <el-form-item label="是否跨一级法人公司">
              <el-radio-group v-model="form.fiskyjfr">
                <el-radio
                  v-for="dict in dict.type.yes_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="状态" prop="fstate">
              <el-select v-model="form.fstate" placeholder="请选择状态">
                <el-option
                  v-for="dict in dict.type.bill_state"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="制单人" prop="fcreator" v-show="show">
              <el-input v-model="form.fcreator" placeholder="请输入制单人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制单时间" prop="fcreatetime" v-show="show">
              <el-date-picker clearable
                 v-model="form.fcreatetime"
                 type="datetime"
                 value-format="yyyy-MM-dd HH:mm:ss"
                 placeholder="请选择制单时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="最后修改人" prop="flastupdateuser" v-show="show">
              <el-input v-model="form.flastupdateuser" placeholder="请输入最后修改人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最后修改时间" prop="flastupdatetime" v-show="show">
              <el-date-picker clearable
                 v-model="form.flastupdatetime"
                 type="datetime"
                 value-format="yyyy-MM-dd HH:mm:ss"
                 placeholder="请选择最后修改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="!show">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPerson, getPerson, delPerson, addPerson, updatePerson } from "@/api/basedata/person";

export default {
  name: "Person",
  dicts: ['bill_state','yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 员工档案表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示控件
      show: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fnumber: null,
        fname: null,
        fsscompany: null/*,
        fsscost: null,
        fgzcdgs: null,
        fgzffgs: null,
        fsbcdgs: null,
        fsbffgs: null,
        fgjjcdgs: null,
        fgjjffgs: null,
        fgzffjrjg: null,
        fgzffyhzh: null,
        fsbffjrjg: null,
        fsbffyhzh: null,
        fgjjffjrjg: null,
        fgjjffyhzh: null,
        fiskyjfr: null,
        fcreator: null,
        fcreatetime: null,
        flastupdateuser: null,
        flastupdatetime: null*/
      },
      // 表单参数
      form: {},
      // 表单校验-修改
      rules: {
        fnumber: [
          { required: true, message: "员工代码不能为空", trigger: "blur" }
        ],
        fname: [
          { required: true, message: "员工名称不能为空", trigger: "blur" }
        ],
        fsscompany: [
          { required: true, message: "一级法人不能为空", trigger: "blur" }
        ],
        fsscost: [
          { required: true, message: "所属成本中心编码不能为空", trigger: "blur" }
        ],
        FssCostName: [
          { required: true, message: "所属成本中心名称不能为空", trigger: "blur" }
        ],
        fgzcdgs: [
          { required: true, message: "工资承担公司不能为空", trigger: "blur" }
        ],
        fgzffgs: [
          { required: true, message: "工资发放公司不能为空", trigger: "blur" }
        ],
        Fcostcompany: [
          { required: true, message: "成本中心所属财务组织不能为空", trigger: "blur" }
        ],
        fsbcdgs: [
          { required: true, message: "社保承担公司不能为空", trigger: "blur" }
        ],
        fsbffgs: [
          { required: true, message: "社保发放公司不能为空", trigger: "blur" }
        ],
        fgjjcdgs: [
          { required: true, message: "公积金承担公司不能为空", trigger: "blur" }
        ],
        fgjjffgs: [
          { required: true, message: "公积金发放公司不能为空", trigger: "blur" }
        ],
        // fgzffjrjg: [
        //   { required: true, message: "工资发放金融机构不能为空", trigger: "blur" }
        // ],
        // fgzffyhzh: [
        //   { required: true, message: "工资发放金融机构银行账户不能为空", trigger: "blur" }
        // ],
        // fsbffjrjg: [
        //   { required: true, message: "社保发放金融机构不能为空", trigger: "blur" }
        // ],
        // fsbffyhzh: [
        //   { required: true, message: "社保发放金融机构银行账户不能为空", trigger: "blur" }
        // ],
        // fgjjffjrjg: [
        //   { required: true, message: "公积金发放金融机构不能为空", trigger: "blur" }
        // ],
        // fgjjffyhzh: [
        //   { required: true, message: "公积金发放金融机构银行账户不能为空", trigger: "blur" }
        // ],
        fiskyjfr: [
          { required: true, message: "是否跨一级法人公司不能为空", trigger: "blur" }
        ],
        fstate: [
          { required: true, message: "状态不能为空", trigger:"blur"}
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询员工档案列表 */
    getList() {
      this.loading = true;
      listPerson(this.queryParams).then(response => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fid: null,
        fnumber: null,
        fname: null,
        fsscompany: null,
        fsscost: null,
        fsscostname: null,
        fgzcdgs: null,
        fgzffgs: null,
        fcostcompany: null,
        fsbcdgs: null,
        fsbffgs: null,
        fgjjcdgs: null,
        fgjjffgs: null,
        fgzffjrjg: null,
        fgzffyhzh: null,
        fsbffjrjg: null,
        fsbffyhzh: null,
        fgjjffjrjg: null,
        fgjjffyhzh: null,
        fiskyjfr: null,
        fcreator: null,
        fcreatetime: null,
        flastupdateuser: null,
        flastupdatetime: null,
        fstate: null,
        show: false
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const fid = row.fid || this.ids
      getPerson(fid).then(response => {
        this.form = response.data;
        this.open = true;
        this.show = true;
        this.title = "查看员工档案";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.show = false;
      this.title = "添加员工档案";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fid = row.fid || this.ids
      getPerson(fid).then(response => {
        this.form = response.data;
        this.open = true;
        this.show = false;
        this.title = "修改员工档案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fid != null) {
            updatePerson(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerson(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fids = row.fid || this.ids;
      this.$modal.confirm('是否确认删除员工档案ID为"' + fids + '"的数据项？').then(function() {
        return delPerson(fids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('basedata/person/export', {
        ...this.queryParams
      }, `person_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
